package cn.schoolwow.flow.monitor.test.module.flowRecord.flow.user;

import cn.schoolwow.flow.monitor.test.entity.User;
import cn.schoolwow.flow.monitor.test.module.test.domain.UserLoginRequest;
import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import org.springframework.context.ApplicationContext;

public class UserLoginSuccessFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String username = (String) flowContext.checkData("username");
        String password = (String) flowContext.checkData("password");
        UserLoginRequest userLoginRequest = flowContext.checkInstanceData(UserLoginRequest.class);
        ApplicationContext applicationContext = flowContext.checkInstanceData(ApplicationContext.class);

        DAO starterDAO = applicationContext.getBean("starterDAO", DAO.class);
        long count = starterDAO.query(User.class)
                .addQuery("username", username)
                .execute()
                .count();
        flowContext.putData("count", count);
    }

    @Override
    public String name() {
        return "用户登录成功";
    }
}
